package com.kfm.hotel.interceptor;

import com.kfm.hotel.util.Constant;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//拦截器
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //从session中获取登录对象
       //Object user = request.getSession().getAttribute("user");
        Object user = request.getSession().getAttribute(Constant.LOGIN_USER);
        //如果是未登录，重定向
        if(user==null){
            response.sendRedirect("/");
            return false;
        }else{
            return true;
        }
        //否则放行
    }
}

